<template>
  <div id="zs">
    <el-dialog :title="'织物全流程追溯'" :visible.sync="addEditIsDialog_c" @close="resetForm('formName')" width="800px" :lock-scroll="false" :append-to-body="true">
      <el-form :model="ruleForm" :rules="rules" ref="formName" label-width="140px" class="demo-ruleForm" :class="{ 'form-rules-show': seeType }">
        <div class="center">
          <div v-for="item in clothLogList" :key="item.id">
            <el-row>
              <el-form-item label="时间：">
                <span class="item-label">{{ item.action_time }}</span>
              </el-form-item>
            </el-row>
            <el-row>
              <el-col :span="8">
                <el-form-item label="操作：">
                  <span class="item-label">{{ item.state }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="操作人：">
                  <span class="item-label">{{ item.operator }}</span>
                </el-form-item>
              </el-col>
              <el-col :span="8">
                <el-form-item label="操作人工号：">
                  <span class="item-label">{{ item.no }}</span>
                </el-form-item>
              </el-col>
            </el-row>
          </div>
        </div>
      </el-form>
      <div slot="footer" class="dialog-footer">
        <el-button @click="resetForm('formName')">关 闭</el-button>
      </div>
    </el-dialog>
  </div>
</template>
<script type="text/ecmascript-6">
import { getClothLog } from "@/api/clothes";

export default {
  components: {},
  props: {
    addEditId: {
      type: String,
      default: "",
    },
    epc: {
      type: String,
      default: "",
    },
    addEditStatus: {
      type: String,
      default: "add",
    },
    addEditIsDialog: {
      type: Boolean,
      default: false,
    },
  },
  data() {
    return {
      ruleForm: {
        // 表单字段
        epc: "",
      },
      rules: {
      },
      addEditIsDialog_c: false, // 弹窗是否显示
      seeType: false, // 是否禁用
      clothLogList: [], // 流程追溯列表
    };
  },
  watch: {
    addEditIsDialog(val) {
      this.addEditIsDialog_c = val;
      if (this.addEditIsDialog_c) {
        // 添加
        if (this.addEditStatus == "add") {
          this.ruleForm.id = "";
          this.seeType = false;
        }

        // 编辑
        if (this.addEditStatus == "edit") {
          this.ruleForm.id = this.addEditId;
          this.ruleForm.epc = this.epc;
          this.seeType = false;
          this.getDetail();
        }

        // 查看
        if (this.addEditStatus == "see") {
          this.ruleForm.id = this.addEditId;
          this.seeType = true;
          this.getDetail();
        }
      }
    },
  },
  methods: {
    // 详情
    getDetail() {
      getClothLog({ epc: this.epc }).then((res) => {
        if (res.code == 200) {
          this.clothLogList = res.data;
        }
      });
    },
    // 关闭
    resetForm() {
      this.$parent.closeAddEdit();
    },
  },
};
</script>

<style lang="less" scoped>
.demo-ruleForm {
  width: 95%;
  margin: 0 auto;
  padding-top: 10px;

  .el-input-number {
    width: 100%;
  }
}
/deep/.el-form-item__label {
  font-size: 1rem;
}
.item-label {
  color: #0218fd;
  font-size: 1rem;
}
.center {
  height: 28rem;
  overflow-y: auto;
}
</style>
